<!--
// 定数定義
var actionName = 'a';
var moduleName = 'm';

// サブミット
function sub_do(frm, mod) {
	sub_all(frm, frm.action_org.value, mod);
}
function sub_all(frm, act, mod) {
	if(!click_chk()) return false;
	
	showLoading();
	
	frm.elements[actionName].value = act;
	frm.elements[moduleName].value = mod;
	if(act != frm.action_org.value) {
		frm.dirty.value = '';
		frm.sort_column.value = '';
		if(frm.search_text != undefined) frm.search_text.value = '';
	}
	frm.submit();
}

function sub_drill(frm, act, key, val) {
	if(act == '' || val == '') return;
	if(act == 'd' || act == 'm' || act == 'w' || act == 'h' || act == 'cv') {
		frm.filter_id.value = val;
		frm.axis_x.value = act;
		sub_list();
		
	} else if(key != '') {
		frm.elements[key].value = val;
		if(frm.filter_id != undefined) frm.filter_id.value = '';
		frm.drill.value = 1;
		frm.sort_column.value = '';
		sub_all(frm, act, 'list');
		
	}
}

function sub_query(mod) {
	if(mod == undefined) mod = 'query';
	
	var frm = document.inputform;
	if(frm == undefined) {
		frm = document.mainform;
		sub_do(frm, mod);
	} else {
		ajax_do(frm, mod, 'id=' + frm.id.value, setFocus);
	}
}

function getInputForm() {
	var frm = document.inputform;
	if(frm == undefined) frm = document.mainform;
	return frm;
}

// 登録処理
var input_check, do_save;
function sub_save(module, msg){
	if(do_save != undefined) return do_save(module, id);
	
	var frm = getInputForm();
	if (input_check != undefined && input_check() == false) return false;
	if( module != 'confirm' && !confirm_regist(msg) ) return false;
	sub_do(frm, module);
}


// ダウンロード
function sub_download(frm, mod) {
	if(mod == undefined) mod = 'download';
	frm.elements[moduleName].value = mod;
	frm.submit();
}

// アップロード
function sub_upload(frm, objName, mod) {
	if(objName != undefined) {
		var file_path = frm.elements[objName].value;
		if(file_path == '') {
			alert("アップロードするファイルを選択してください。");
			return false;
		} else if(!isUploadableFilePath(file_path)) {
			alert("ファイルの指定が不正です。");
			return false;
		}
	}

	if(!window.confirm("アップロードします。\nよろしいですか？")) return false;
	if(mod == undefined) mod = 'upload';
	sub_do(frm, mod);
}

function isUploadableFilePath(file_path) {
	// IEの場合、Windows形式の絶対パスしか指定できない
	if (document.all) {
		if(file_path.match(/^[A-Z]:\\.+/i)) return true;
		if(file_path.length > 2 && file_path.substring(0, 2)=='\\\\') return true;
		return false;
	}
	return true;
}

// キャッシュの指定を外すためのパラメータ
function param_nocache() {
	var tv = (new Date).getTime();
	return '&nocache=' + tv;
}

// アンカータグの代わり
function sub_redirect(act, args) {
	var pars = 'a=' + act;
	if(args != undefined && args != '') {
		if(args.charAt(0) != '&') args = '&' + args;
		pars += args;
	}
	var frm = document.mainform;
	if(frm != undefined && frm.topmenu_display != undefined) pars += '&topmenu_display=' + frm.topmenu_display.value;
	pars += param_nocache();
	
	showLoading();
	
	var url = 'index.php?' + pars;
	location.href = url;
}

// 削除
function sub_delete(msg){
	var frm = document.mainform;
	if(sub_delete_proc(frm, 'sel') == false) return false;
	sub_do(frm, 'delete');

}

function sub_delete_proc(frm, obj_name, msg){
	var ids = getSelIds(frm, obj_name);
	if( ids == '' ) {
		alert("削除する対象を選択してください。");
		return false;
	}
	if(msg == undefined || msg == '') msg = "削除します。\nよろしいですか？";
	if( !window.confirm(msg) ) return false;
	frm.del_ids.value = ids;
	return true;
}

// 確認
function confirm_regist(msg){
	if(msg == undefined || msg == '') msg = "登録";
	msg = msg + "します。\nよろしいですか？";
	return window.confirm(msg);
}
function confirm_delete(){
	return confirm_regist("削除");
}

// 絞込
function sub_filter(){
	var frm = document.mainform;
	var ids = getSelIds(frm, 'sel');
	if( ids == '' ) {
		alert("絞り込む対象を選択してください。");
		return false;
	}
	frm.sel_ids.value = ids;	
	sub_do(frm, 'list');

}
function sub_filter_reset(){
	var frm = document.mainform;
	frm.sel_ids.value = '';	
	sub_do(frm, 'list');

}

function getSelIds(frm, obj_name, noneIsAll) {
	var ids = '';
	var isAll = true;
	var elements = document.getElementsByName(obj_name);
	for(var i = 0; i < elements.length; i++) {
		if(elements[i].form != frm) continue;
		if(elements[i].checked) {
			if(ids != '') ids += ',';
			ids += elements[i].value;
		} else {
			isAll = false;
		}
	}
	
	if(noneIsAll != undefined && noneIsAll && isAll) {
		ids = '';
	}
	
	return ids;
}


// 一覧
function sub_list(){
	var frm = document.mainform;
	if(frm.from_date != undefined && !checkDate(frm.from_date, '日付')) return false;
	if(frm.to_date != undefined && !checkDate(frm.to_date, '日付')) return false;
	sub_do(frm, 'list');
	return false;
}

function sub_list_clear(ids){
	var frm = document.mainform;
	var arr = ids.split(",");
	for(var i = 0; i < arr.length; i++) {
		var id = trim(arr[i]);
		if(id == '') continue; 
		if(frm.elements[id] == undefined) continue;
		frm.elements[id].value = '';
	}
	sub_list();
}

// ページ行切替
function sub_change_lines(lines){
	var frm = document.mainform;
	sub_change_lines_proc(frm, lines);
	frm.elements['control'].value = 'page';
	sub_list();
}
function sub_change_lines_proc(frm, lines){
	frm.elements['lines_per_page'].value = lines;
	frm.elements['page_no'].value = 1;
}

// ページ切替
function sub_change_page(page_no){
	var frm = document.mainform;
	frm.elements['page_no'].value = page_no;
	frm.elements['control'].value = 'page';
	sub_list();
}
function sub_add_page(offset, page_no, page_max){
	var frm = document.mainform;
	sub_add_page_proc(frm, offset, page_no, page_max);
	frm.elements['control'].value = 'page';
	sub_list();
}
function sub_add_page_proc(frm, offset, page_no, page_max){
	var new_no = page_no + offset;
	if(new_no < 1) new_no = 1;
	if(new_no > page_max) new_no = page_max;
	frm.elements['page_no'].value = new_no;
}

// 並べ替え
function sub_sort(sort_column, sort_order){
	var frm = document.mainform;
	sub_sort_proc(frm, sort_column, sort_order);
	frm.elements['control'].value = 'sort';
	sub_list();
}
function sub_sort_proc(frm, sort_column, sort_order){
	var org_column = frm.elements['sort_column'].value;
	var org_order = frm.elements['sort_order'].value;
	if(org_column == sort_column) {
		sort_order = (org_order == 'desc' ? 'asc' : 'desc');
	}
	frm.elements['sort_column'].value = sort_column;
	frm.elements['sort_order'].value = (!sort_order ? 'asc' : sort_order);
}

// 削除チェック
function change_check(each_name, all_id){
	var frm = document.mainform;
	change_check_proc(frm, each_name, all_id);
}
function change_check_proc(frm, each_name, all_id){
	var elements = document.getElementsByName(each_name);
	var all_checked = true;
	for(var i = 0; i < elements.length; i++) {
		if(elements[i].form != frm) continue;
		if(elements[i].checked == false) {
			all_checked = false;
			break;
		}
	}
	var objAll = getObjById(all_id);
	objAll.checked = all_checked;
}




// エクスポート
function sub_export(mod){
	var frm = document.exportform;
	frm.elements[actionName].value = 'common/export/Export';
	frm.elements[moduleName].value = mod;
	frm.submit();	
}

function changeTableDisplayType(type) {
	var frm = document.mainform;
	frm.table_display_type.value = type;
	sub_list();
}

// メッセージ表示
function show_alert_msg(msg) {
	var alerter = function() {
		alert(msg);
	}
	setTimeout(alerter, 0);
}

function get_chart_width() {
	// ウィンドウ幅を取得
	var width = getWindowWidth();
	if(width == 0) width = 1000;
	if(width < 400) width = 400;
	
	// メニューを表示しているならその分をひく
	width -= 200;

	// チャートの幅は、その他余白を引いた分
	width -= 80;
	
	return width;
}

function get_chart_height(width, size) {
	var height = 175;
	if(size == 2) {
		// 大
		height = getWindowHeight();
		if(height <= 700) height = 700;
		height -= 300;
	}
	return height;
}

var div_loading = null;
preloadImage("view/images/loading.gif");
function makeDivLoading(){

	var div = document.createElement("div");

	div.className = 'div_loading';

	div.style.height = 50 + 'px';
	div.style.width = 200 + 'px';
	
	div.appendChild(document.createTextNode("Now Loading ..."));
	div.appendChild(document.createElement("br"));
	
	var img = document.createElement("img");
	img.className = 'img_loading';
	img.setAttribute("src", 'view/images/loading.gif');
	img.setAttribute("alt", "...");
	img.setAttribute("title", "...");
	
	div.appendChild(img);
	
	return div;
}

function showLoading() {
	if(div_loading != null) return;
	
	div_loading = makeDivLoading();
	
	var wx = wy = 200;
	if(document.documentElement && document.documentElement.clientWidth != 0) {
		wx=document.documentElement.clientWidth;
		wy=document.documentElement.clientHeight;
	} else if(document.body) {
		wx=document.body.clientWidth;
		wy=document.body.clientHeight;
	} else if(document.body.innerWidth) {
		wx=screen.width;
		wy=screen.height;
	} 
	
	div_loading.style.top = (wy - 50 - parseInt(div_loading.style.height)) / 2 + document.documentElement.scrollTop + 'px';
	div_loading.style.left = (wx - parseInt(div_loading.style.width)) / 2 + document.documentElement.scrollLeft + 'px';

	document.body.appendChild(div_loading);
}
//-->
